import {
  post,
  ajaxSetup,
} from "jquery"
import * as interfaces from './Interfaces.json'
import Tracker from './Tracker.js';
import Agent from './Agent.js';

function csrfSafeMethod(method) {
  // these HTTP methods do not require CSRF protection
  return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}

// 添加csrf 验证
// 添加日志
ajaxSetup({
  beforeSend: function (xhr, settings) {
    if (process.env.NODE_ENV === 'production') {
      const host = 'cn-qingdao.log.aliyuncs.com';
      const project = 'htetest1';
      const logstore = 'htenewweblog';
      let log = new Tracker(host, project, logstore);
      if (settings.data) {
        log.push('_params_', settings.data);
        let data = settings.data.split('&')
        for (let v in data) {
          let to = data[v].split('=');
          if (to[0].replace(/\s+/g, "") === "uid") {
            log.push('_uid_', to[1]);
          }
          if (to[0].replace(/\s+/g, "") === "cid") {
            log.push('_cid_', to[1]);
          }
          if (to[0].replace(/\s+/g, "") === "ips") {
            log.push('_ip_', to[1]);
          }
        }
      }
      log.push('_method_', settings.url);
      log.push('_type_', settings.type);
      log.push('_error_', xhr.responseJSON && xhr.responseJSON.error);
      log.push('_topic_', 'htewebhome');
      new Agent(log);
      log.logger()
    }

    if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
      let arr = document.cookie.split(';')
      for (let v in arr) {
        let to = arr[v].split('=');
        if (to[0].replace(/\s+/g, "") === "csrfToken") {
          xhr.setRequestHeader('x-csrf-token', to[1].replace(/\s+/g, ""));
        }
      }
    }
  },
});
export const asynclogin = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.login, data).then(response => {
      if (response.error == 0) {
        window.userid = response.data.userid
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncloginphonenum = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.loginphonenum, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function () {

      reject('服务器开小差了')
    })
  })
}

export const session = function () {
  return new Promise((resolve, reject) => {
    post(interfaces.online).then(response => {
      if (response.error == 0) {
        window.userid = response.data.userid
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}



export const getallcourse = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.AllCourse, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// export const packagekey = function (data) {
//   return new Promise((resolve, reject) => {
//     post(interfaces,data).then(response => {
//       if (response.error == 0) {
//         resolve(response.packagekey)
//       } else {
//         reject(response.msg)
//       }
//     }).catch(function (error) {
//       console.log(error);
//       reject('服务器开小差了')
//     })
//   })
// }











































// 提交答案 
export const asynccheckQuestion = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.checkQuestion, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 创建学生

export const asyncnewstudent = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.newStudent, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 获取视频信息

export const asyncgetvideoInfo = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.videoInfo, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 通过course id 获取 lession
export const asyncgetLessionByCourseid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getLessionByCourseid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 获取用户课程

export const asyncgetktUser = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getCourse, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 获取推荐课程

export const asyncgetTuijian = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.AllCourse, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 获取课堂信息
export const asyncgetktById = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.CourseInfo, data).then(response => {
      if (response.error == 0) {
        resolve(response.courses)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncupdate = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.update, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 支付宝接口
export const asyncpay = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.pay, data, "text").then(response => {
      resolve(response.data)
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 重置密码

export const asyncchangePassword = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.changePassword, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncUserCourseInfo = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.UserCourseInfo, data).then(response => {
      if (response.error == 0) {

        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log("11112121212", error);
      reject('服务器开小差了')
    })
  })
}

export const asyncgetLessionByCourseidAndNum = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getLessionByCourseidAndNum, data).then(response => {
      if (response.error == 0) {

        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 刷新用户学到第几节
export const asynclearn = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.learn, data).then(response => {
      if (response.error == 0) {

        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 获取支付宝支付接口
export const asynpay = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.pay, data).then(response => {

      resolve(response.data)
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 添加收藏
export const asynaddCollection = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.addCollection, data).then(response => {
      if (response.error == 0) {

        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 用户注册
export const asyncregist = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.regist, data).then(response => {
      if (response.error == 0) {

        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 获取子用户
export const asyncgetChildren = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getChildren, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 获取课程包
export const asyncgetInvite = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getInvite, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 审核子用户
export const asynccheckUser = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.checkUser, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncgetCourseFile = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getCourseFile, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 获取yzm
export const asyncfind_getCode = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.find_getCode, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 检查yzm
export const asyncfind_checkCode = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.find_checkCode, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}


// 修改密码
export const asyncfind_findPassword = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.find_findPassword, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}


// 注册获取yzm
export const asyncregist_getCode = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.regist_getCode, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}




// 获取微信支付
export const asyncWXpay = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.WXpay, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 站内信
// 创建消息
export const asyncnewMessage = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.newMessage, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 查询收到消息
export const asyncreceivedMessage = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.receivedMessage, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 查询发送消息
export const asyncsentMessage = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.sentMessage, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 标记消息已读
export const asyncreadMessage = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.readMessage, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}









// wx获取验证码
export const asyncgetLoginQRCode = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getLoginQRCode, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// wx绑定
export const asyncgetBindQRCode = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getBindQRCode, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// // wxWXBindPhone
// export const asyncWXBindPhone = function (data) {
//   return new Promise((resolve, reject) => {
//     post(interfaces.WXBindPhone).then(response => {
//       if (response.error == 0) {
//         resolve(response.data)
//       } else {
//         reject(response.msg)
//       }
//     }).catch(function (error) {
//       console.log(error);
//       reject('服务器开小差了')
//     })
//   })
// }

// // wxbindWXBindUser
// export const asyncWXBindUser = function (data) {
//   return new Promise((resolve, reject) => {
//     post(interfaces.WXBindUser).then(response => {
//       if (response.error == 0) {
//         resolve(response.data)
//       } else {
//         reject(response.msg)
//       }
//     }).catch(function (error) {
//       console.log(error);
//       reject('服务器开小差了')
//     })
//   })
// }

// WXAuthorize
export const asyncWXAuthorize = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.WXAuthorize).then(response => {
      if (response.error == 0) {
        resolve(response.data, data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 免费课程
export const asyncForfeepay = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.Forfeepay, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 查询用户积分
export const asyncgetUserAllPoint = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getUserAllPoint, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 查询某个用户的类别分
export const asyncgetuserTypePoint = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getUserTypePoint, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}




































































// 创建课程资料
export const asyncuploadCoursefile = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.uploadCoursefile, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 删除课程资料
export const asyncdeleteCoursefile = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.deleteCoursefile, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 修改课程资料
export const asyncupdateCoursefile = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.updateCoursefile, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 查询课程资料
export const asyncselectCoursefile = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.selectCoursefile, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}






// 查询视频调整
export const asyncselectWhitepoint = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.selectWhitepoint, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}


//课程打包
//显示所有的课程组
export const showbag = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.showbag, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}


//从课程封面点击进去查看内部课程
export const selectcoursebybid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.selectcoursebybid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

//绑定微信
export const bindwechat = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.bindwechat, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
        // resolve(response.data, response.error)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

//获取所有课程组
export const getAllCatebag = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getAllCatebag, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}







// 获取该课程组下的所有课程
export const getCourseByCatabagid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getCourseByCatabagid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}





// 获取iframe
export const asyncgetiframebyid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getiframebyid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 获取iframe
export const asyncgetiframebycourseid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getiframebycourseid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}


// 获取getCoursecountByCatabagid 数量
export const asyncgetCoursecountByCatabagid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getCoursecountByCatabagid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 通过id获取课程组
export const asyncgetcatebagsbyid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getcatebagsbyid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}


//获取所有课程组类型
export const getAllCatebagtype = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getAllCatebagtype, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}








export const asyncgetuserUsercourse = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getuserUsercourse, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}



export const wechatsignature = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.wechatsignature, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncdelwxopid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.delwxopid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncforum = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.forum, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asynccreatetopic = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.createtopic, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncupdatetopic = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.updatetopic, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncdelecttopicbyid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.delecttopicbyid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncgettopicbyid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.gettopicbyid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncgettopicbyuser = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.gettopicbyuser, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}


export const asyncgettopic = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.gettopic, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncgetreply = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getreply, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asynccreatereply = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.createreply, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asynctopiccount = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.topiccount, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}


export const asynccreatetopiccollect = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.createtopiccollect, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncgettopiccollectbyuser = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.gettopiccollectbyuser, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncgetusercollect = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getusercollect, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncgetuserreply = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getuserreply, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncgetuserreplyfabulous = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getuserreplyfabulous, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncgetusertopic = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getusertopic, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asynccreaterepcyfabulous = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.createrepcyfabulous, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

//创建作品
export const asynccreateshare = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.createshare, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//修改作品
export const asyncupdateshare = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.updateshare, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//通过id删除作品
export const asyncdelectsharebyid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.delectsharebyid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//通过id获取作品
export const asyncgetsharebyid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getsharebyid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//获取自己所有作品
export const asyncgetsharebyuser = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getsharebyuser, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//获取所有已审核的作品
export const asyncgetshare = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getshare, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//给作品点赞或者取消
export const asynccreatesharefabulous = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.createsharefabulous, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//通过id获取作品已经点赞
export const asyncgetsharefabulousbyid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getsharefabulousbyid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//创建作品评论
export const asynccreatesharecomment = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.createsharecomment, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//通过id删除作品评论
export const asyncdelectsharecommentbyid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.delectsharecommentbyid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//通过id获取评论
export const asyncgetsharecomment = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getsharecomment, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//给评论点赞或者取消
export const asynccreatesharecommentfabulous = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.createsharecommentfabulous, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//获取评论是否点赞
export const asyncgetsharecommentfabulousbyid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getsharecommentfabulousbyid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}
//上传权限
export const asyncossupload = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.ossupload, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

//获取作品数量
export const asyncgetsharecount = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getsharecount, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}






//获取秘密文件
export const asyncgetsecretfile = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getsecretfile, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}



// 查询所有课程包课程
export const asyncgetcoursecatebag = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getcoursecatebag, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}










// 查询所有课程包课程
export const asyncgetteacherproposal = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getteacherproposal, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 查询所有课程包课程
export const asyncgettpdata = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.gettpdata, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}


// 查询所有问题
export const asyncgetitembank = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getitembank, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}







// 查询所有问题
export const asyncgetitembankgroup = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getitembankgroup, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}







// 获取
export const asyncgetitembankitembankgroup = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getitembankitembankgroup, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 创建修改
export const asynccreateitembankitembankgroup = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.createitembankitembankgroup, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 创建修改
export const asynccreateteacheritembank = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.createteacheritembank, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 修改测试题
export const asyncupdateteacheritembank = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.updateteacheritembank, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 删除测试题
export const asyncdelteacheritembank = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.delteacheritembank, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 创建修改
export const asyncgetteacheritembank = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getteacheritembank, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 创建添加删除答题
export const asynccreateteacheritembankitembank = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.createteacheritembankitembank, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 获取教师自己用户的答题
export const asyncgetanswerinteacher = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.getanswerinteacher, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

// 更新用户答题是否已经查看
export const asyncupdateanswer = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.updateanswer, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

//获取usertoypdata。id的数据
export const asyncselectallusertotpdataidd = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.selectallusertotpdataidd, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncInquireusertotpdataid = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.Inquireusertotpdataid, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncaddteachertextitembank = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.addteachertextitembank, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncselectteachertextitembank = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.selectteachertextitembank, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncdelteachertextitembank = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.delteachertextitembank, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

export const asyncselecttestanswer = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.selecttestanswer, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
}

/* export const asyncselectteachertextitembank = function (data) {
  return new Promise((resolve, reject) => {
    post(interfaces.selectteachertextitembank, data).then(response => {
      if (response.error == 0) {
        resolve(response.data)
      } else {
        reject(response.msg)
      }
    }).catch(function (error) {
      console.log(error);
      reject('服务器开小差了')
    })
  })
} */